<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
        $datetime = date('Y-m-d H:i:s');
        Log::info('===================================================');
        Log::info("当前定时任务执行时间：$datetime");

        $schedule->call(function () {
            Log::info("执行任务：****** 更新京东商品价格 ******");
            checkJdGoodsPrice();
        })->dailyAt('00:10');

        $schedule->call(function () {
            Log::info('执行任务：****** 机器人购买商品 ******');
            $rand = rand(1, 100);
            if ($rand % 2 == 0) {
                Log::info('###### 执行购买 ######');
                robotBuyProduct();
            }
        })->everyMinute()->between('7:00', '23:00');

        $schedule->call(function () {
            Log::info('执行任务：****** 取消超时未付款的订单 ******');
            checkOrderPayStatus();
        })->everyMinute();

        $schedule->call(function () {
            Log::info("执行任务：****** 超过7天的订单自动完成，并计算佣金 ******");
            checkUnCompletedOrder();
        })->dailyAt('00:00');

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
